package march.finalmarch22.march03;

import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;

import java.io.IOException;

public class StuRecordWriter03 extends RecordWriter<Text, NullWritable> {

    private FSDataOutputStream outputStream;


    public StuRecordWriter03(TaskAttemptContext job){

        try{
            FileSystem fs = FileSystem.get(job.getConfiguration());
            outputStream = fs.create(new Path("F:\\test00\\Top\\sub_top3"));
        }catch (IOException e){
            e.printStackTrace();
        }
    }

    @Override
    public void write(Text key, NullWritable value) throws IOException, InterruptedException {
        outputStream.writeBytes(key+"\n");
    }

    @Override
    public void close(TaskAttemptContext context) throws IOException, InterruptedException {

        IOUtils.closeStream(outputStream);
    }
}
